import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/modules/application/double_prevention_page/risk_control_page/instrument_monitoring_ledger_page/instrument_monitoring_ledger_detail/instrument_monitoring_ledger_detail_controller.dart';
import 'package:syncfusion_flutter_charts/charts.dart';

///仪表监测台账详情
class InstrumentMonitoringLedgerDetailPage extends StatelessWidget {
  InstrumentMonitoringLedgerDetailPage({super.key});

  final controller = Get.put(InstrumentMonitoringLedgerDetailController());

  @override
  Widget build(BuildContext context) {
    return RotatedBox(
      quarterTurns: 3,
      child: Scaffold(
        body: Column(
          children: [
            _buildTitle(),
            _buildContent(),
          ],
        ),
      ),
    );
  }

  /// 线性图
  Widget _lineChar() {
    return SizedBox(
      height: 260, // 设置图表高度
      child: SfCartesianChart(
        // title: ChartTitle(text: '多条折线图示例'),
        //用于配置图例，可以控制图例的可见性、位置、对齐方式等。
        legend: const Legend(
          isVisible: true,
          // position: LegendPosition.bottom,
          overflowMode: LegendItemOverflowMode.scroll,
        ),
        //用于配置图表的主轴（x 轴和 y 轴），可以设置标题、标签、刻度线、范围等属性
        primaryXAxis: NumericAxis(),
        primaryYAxis: NumericAxis(),
        trackballBehavior: TrackballBehavior(
          enable: true,
          lineDashArray: const [10],
          lineColor: Colors.grey,
          lineWidth: 1,
          activationMode: ActivationMode.singleTap,
          shouldAlwaysShow: true,
          tooltipDisplayMode: TrackballDisplayMode.groupAllPoints,
          tooltipSettings: const InteractiveTooltip(
              enable: true, color: Colors.white, borderColor: Colors.grey, connectorLineColor: Colors.transparent, textStyle: TextStyle(color: Colors.black)),
        ),
        series: <ChartSeries>[
          LineSeries<DataPoint, double>(
            name: '高报',
            dataSource: <DataPoint>[
              DataPoint(0, 10),
              DataPoint(1, 20),
              DataPoint(3, 30),
              DataPoint(5, 30),
              DataPoint(6, 30),
              DataPoint(7, 30),
              DataPoint(9, 30),
              // 添加更多的数据点
            ],
            xValueMapper: (DataPoint data, _) => data.x,
            yValueMapper: (DataPoint data, _) => data.y,
          ),
          LineSeries<DataPoint, double>(
            name: '高高报',
            dataSource: <DataPoint>[
              DataPoint(0, 10),
              DataPoint(2, 20),
              DataPoint(4, 30),
              DataPoint(6, 30),
              DataPoint(9, 30),
              DataPoint(12, 30),
              DataPoint(13, 30),
              // 添加更多的数据点
            ],
            xValueMapper: (DataPoint data, _) => data.x,
            yValueMapper: (DataPoint data, _) => data.y,
          ),
          LineSeries<DataPoint, double>(
            name: '低报',
            dataSource: <DataPoint>[
              DataPoint(0, 10),
              DataPoint(12, 20),
              DataPoint(12, 30),
              DataPoint(13, 30),
              DataPoint(14, 30),
              DataPoint(15, 30),
              DataPoint(17, 30),
              // 添加更多的数据点
            ],
            xValueMapper: (DataPoint data, _) => data.x,
            yValueMapper: (DataPoint data, _) => data.y,
          ),
          LineSeries<DataPoint, double>(
            name: '低低报',
            dataSource: <DataPoint>[
              DataPoint(0, 10),
              DataPoint(1, 20),
              DataPoint(3, 30),
              DataPoint(5, 30),
              DataPoint(6, 30),
              DataPoint(7, 30),
              DataPoint(9, 30),
              // 添加更多的数据点
            ],
            xValueMapper: (DataPoint data, _) => data.x,
            yValueMapper: (DataPoint data, _) => data.y,
          ),
          // 添加更多的线
        ],
      ),
    );
  }

  /// 内容
  Widget _buildContent() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        contentTittle(),
        _lineChar(),
      ],
    );
  }

  /// 内容的头部
  Widget contentTittle() {
    return Container(
      margin: EdgeInsets.only(left: 10.w, top: 10.w, bottom: 5.w),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            'XXX任务名称',
            style: TextStyle(
              fontSize: 13.sp,
              color: const Color(0xFF495061),
              fontWeight: FontWeight.w500,
            ),
          ),
          AppGaps.vGap5,
          Text(
            'XX对象-XX单元-XX事件-XXX措施',
            style: TextStyle(
              fontSize: 13.sp,
              color: const Color(0xFF495061),
              fontWeight: FontWeight.w500,
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildTitle() {
    return Container(
      height: 40.w,
      alignment: Alignment.center,
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
          bottom: BorderSide(
            color: AppColors.divider_color_blue,
            width: 1.w,
          ),
        ),
      ),
      child: Row(
        children: [
          IconButton(onPressed: Get.back, icon: const Icon(Icons.arrow_back)),
          AppGaps.hGap10,
          Text(
            '历史曲线图',
            style: TextStyle(
              fontSize: 16.sp,
              fontWeight: FontWeight.w500,
            ),
          ),
        ],
      ),
    );
  }
}

class DataPoint {
  DataPoint(this.x, this.y);

  final double x;
  final double y;
}
